package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.config.MinioConstantProperties;
import com.atguigu.tingshu.album.service.FileService;
import com.atguigu.tingshu.common.result.Result;
import io.minio.*;
import io.minio.errors.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.apache.commons.io.FilenameUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;

@Tag(name = "上传管理接口")
@RestController
@RequestMapping("api/album")
public class FileUploadApiController {



    @Autowired
    private FileService fileService;

    //  http://127.0.0.1/api/album/fileUpload --dev

    /**
     * 文件上传 springmvc 文件上传类
     * @return
     */
    @Operation(summary = "文件上传")
    @PostMapping("fileUpload")
    public Result fileUpload(MultipartFile file){
        //  调用服务层方法。
        String url = fileService.fileUpload(file);
        return Result.ok(url);
    }




    public static void main(String[] args) {
        String fileName = "atguigu.jpg";
        //  使用
        String file = UUID.randomUUID().toString().replaceAll("-","");
        System.out.println(FilenameUtils.getExtension(fileName));

    }
}
